package com.tuju.jetpackfirstdemo.ui.rv_demo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.tuju.jetpackfirstdemo.R
import com.tuju.jetpackfirstdemo.adapter.DemoRvAdapter
import com.tuju.jetpackfirstdemo.widget.MyItemDecoration
import kotlinx.android.synthetic.main.activity_rv_demo.*
import java.util.*

class RvDemoActivity : AppCompatActivity() {

    lateinit var adapter: DemoRvAdapter

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_rv_demo)
        rv_demo.layoutManager = LinearLayoutManager(this@RvDemoActivity)
//        rv_demo.layoutManager = GridLayoutManager(this, 2, GridLayoutManager.HORIZONTAL, false)
        adapter = DemoRvAdapter()
        rv_demo.adapter = adapter
        rv_demo.addItemDecoration(MyItemDecoration())
        initData()
    }

    private fun initData() {
        val datas = Arrays.asList("哈哈1", "嘿嘿2", "嘿嘿3", "嘿嘿4", "嘿嘿5", "嘿嘿6", "嘿嘿7", "嘿嘿8", "嘿嘿9", "嘿嘿10", "哈哈11"
                , "哈哈1", "嘿嘿2", "嘿嘿3", "嘿嘿4", "嘿嘿5", "嘿嘿6", "嘿嘿7", "嘿嘿8", "嘿嘿9", "嘿嘿10", "哈哈11")
        adapter.addAll(datas)
        adapter.notifyDataSetChanged()
    }


}
